import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { UserErrorService } from './user_error.service';
import { CreateUserErrorDto } from './dto/create-user_error.dto';
import { UpdateUserErrorDto } from './dto/update-user_error.dto';
import { UserError } from './entities/user_error.entity';
import { BaseController } from 'src/common/BaseController';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { QueryListDto } from 'src/common/dto/';
@ApiTags('错题库')
@Controller('user-error')
export class UserErrorController extends BaseController<UserError, UserErrorService> {
  constructor(private readonly userErrorService: UserErrorService) {
    super(userErrorService);
  }

  @Post('add_error_book')
  @ApiOperation({ summary: '创建错题库' })
  //@ApiResponse({ status: 200, description: '添加成功', type: ErrorBook })
  create(@Body() CreateUserErrorDto: CreateUserErrorDto) {
    return this.Success( this.userErrorService.create(CreateUserErrorDto), '创建成功');
  }

  // @Get()
  // findAll() {
  //   return this.userErrorService.findAll();
  // }

  @Get(':userId')
  @ApiOperation({ summary: '根据用户id查找错题' })
  async findByUserId(@Param('userId') userId: string) {
    let result = await this.userErrorService.findByUserId(userId);
    
    if (result[0]) {
      return this.Success(result[1], "查询成功");
    } else {
      return this.Fail(result[1], "查询失败");
    }
  }

  @Patch('Update_error')
  @ApiOperation({ summary: '错题更新' })
  async update(@Body() updateUserErrorDto: CreateUserErrorDto) {
    let result = await this.userErrorService.update(updateUserErrorDto);
    if(result[0]){
      return this.Success(result[1], "更新成功");
    }else{
      return this.Fail(result[1], "更新失败");
    }
  }
  

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userErrorService.remove(id);
  }
}
